package day7;

import java.sql.SQLOutput;
import java.util.*;

public class TestTreeSet {
    public static void main(String[] args) {
        //Set<String> set=new TreeSet<>();
        //1.数字的TreeSet默认升序排序
        Set<Integer> set1=
                new TreeSet<>(Arrays.asList(3,1,2,4,8,11,8));//不管是否重复 默认去重
        System.out.println(set1);
        //2.String类：按位比较ASCII
        Set<String> set2=
                new TreeSet<>(Arrays.asList("a","b","c","1a"));
        Set<String> set3=new TreeSet<>((o1,o2)->o2.compareTo(o1));//降序
        set3.addAll(set2);
        System.out.println(set3);
        //3.对象类排序:斗地主针对牌对象排序
        //Set<> set2=new TreeSet<>();
        //Integer[] nums={1,2,3,4,5};
        //List<Integer> list= Arrays.asList(nums); //不可变
        //System.out.println(list);
        //list.add(100);不可以执行 因为asList不可变
        Set<Card> set4=new TreeSet<>(((o1, o2) -> {
            int i=o2.num-o1.num;//根据数值排序
            if(i==0)  i=o1.str.compareTo(o2.str);//如果数值相同 再根据花色排序
            return i;
        }) );
        //定义所有的牌对象 定义存储list所有的牌对象
        String[] color={"♣","♦","♠","♥"};
        String[] nums={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        List<Card> cards=new ArrayList<>();//存储所有牌
        for(String s:color){
            for(int i=0;i< nums.length;i++){
               cards.add(new Card(s+nums[i],i+3));
            }
        }
        cards.add(new Card("小🃏",16));
        cards.add(new Card("大🃏",17));
        System.out.println(cards);
        //Collections.shuffle(cards); //打乱顺序
        Random r=new Random();
        for(int i=0;i<14;i++){
            int index=r.nextInt(cards.size());
            set4.add(cards.get(index));
        }
        System.out.println(set4);
    }

}
class Card{
    String str;//存储内容 ♣10
    int num;//存储牌对应的数值

    public Card(String str, int num) {
        this.str = str;
        this.num = num;
    }

    @Override
    public String toString() {
        return str;
    }
}